<?php
class Z3xemkenhsController extends AppController {

	var $name = 'Z3xemkenhs';

	function index() {
		$this->Z3xemkenh->recursive = 0;
		$this->set('z3xemkenhs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid z3xemkenh', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('z3xemkenh', $this->Z3xemkenh->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Z3xemkenh->create();
			if ($this->Z3xemkenh->save($this->data)) {
				$this->Session->setFlash(__('The z3xemkenh has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The z3xemkenh could not be saved. Please, try again.', true));
			}
		}
		$loaikenhs = $this->Z3xemkenh->Loaikenh->find('list');
		$donvis = $this->Z3xemkenh->Donvi->find('list');
		$nhanviens = $this->Z3xemkenh->Nhanvien->find('list');
		$this->set(compact('loaikenhs', 'donvis', 'nhanviens'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid z3xemkenh', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Z3xemkenh->save($this->data)) {
				$this->Session->setFlash(__('The z3xemkenh has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The z3xemkenh could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Z3xemkenh->read(null, $id);
		}
		$loaikenhs = $this->Z3xemkenh->Loaikenh->find('list');
		$donvis = $this->Z3xemkenh->Donvi->find('list');
		$nhanviens = $this->Z3xemkenh->Nhanvien->find('list');
		$this->set(compact('loaikenhs', 'donvis', 'nhanviens'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for z3xemkenh', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Z3xemkenh->delete($id)) {
			$this->Session->setFlash(__('Z3xemkenh deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Z3xemkenh was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
